package cn.bgs.controller;


import cn.bgs.common.AliOss;
import cn.bgs.common.R;
import cn.bgs.pojo.Community;
import cn.bgs.common.R;
import cn.bgs.pojo.Community;
import cn.bgs.service.ICommunityService;
import cn.bgs.vo.CommunitysVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 小区表 前端控制器
 * </p>
 *
 * @author cf
 * @since 2022-06-07
 */
@RestController
@RequestMapping("/community")
public class CommunityController {

    @Autowired
    private ICommunityService iCommunityService;

    @GetMapping("/appFindAllCommunity")
    @ApiOperation(value = "app我的房屋(添加房屋的小区查询)")
    public R appFindAllCommunity(){
        List<Community> community = iCommunityService.appFindAllCommunity();
        if (community != null){
            return R.ok().data("community",community);
        }else {
            return R.error();
        }
    }
    @Autowired
    private AliOss aliOss;

    @GetMapping("findCommunity")
    public R findCommunity(){
        return iCommunityService.findCommunity();
    }

    @PostMapping("addCommunity")
    public R addCommunity(@RequestBody CommunitysVo community){
        return iCommunityService.addCommunity(community);
    }

    @PostMapping("updateCommunity")
    public R updateCommunity(@RequestBody CommunitysVo community){
        System.out.println(community.getBuiltTime()+"1111111111111111111111111111111111");
        return iCommunityService.updateCommunity(community);
    }

    @RequestMapping("/upload")
    @ApiOperation(value = "小区图片")
    public String upload(MultipartFile file){

        String file1 = aliOss.upload(file);
        System.out.println(file1);

        return file1;
    }

    @GetMapping("delCommunity/{communityId}")
    public R delCommunity(@PathVariable("communityId") Integer communityId){
        return iCommunityService.delCommunity(communityId);
    }
}
